/*
 * 文件名：LocalTemporaryCheckServiceImpl.java	 
 * 时     间：上午11:27:50
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.dao.mapers.LocalRepeatImportMapper;
import com.local.manager.locks.RepeatStaticEntity;
import com.local.model.LocalRepeatImport;
import com.local.model.LocalRepeatImportExample;
import com.local.service.face.LocalRepeatImportService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.entity.PageInfo;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.Tools;
import com.qianhai.common.utils.UUIDGenerateUtil;

/** 
 * 类描述:这里是类描述
 * @ClassName: LocalTemporaryCheckServiceImpl 
 * @author Administrator
 * @date 2015年10月6日 上午11:27:50 
 */

@Service
public class LocalRepeatImportServiceImpl  extends BaseServiceImpl<LocalRepeatImportExample, LocalRepeatImport, String> implements
	LocalRepeatImportService
{
	
	@Autowired
	private LocalRepeatImportMapper localRepeatImportMapper;
	

	@Override
	public String saveOrUpdateLocalRepeatImport(LocalRepeatImport localRepeatImport)
	{
		// TODO Auto-generated method stub
				try
				{
					List<LocalRepeatImport> list=localRepeatImportMapper.queryByPage(new PageInfo<LocalRepeatImport>());
					if("1".equals(localRepeatImport.getType())||Tools.isEmpty(localRepeatImport.getType())){
						RepeatStaticEntity.instance().setRepeatStaticLock(true);
					}else{
						RepeatStaticEntity.instance().setRepeatStaticLock(false);
					}
					if (!Tools.isEmpty(list) && !list.isEmpty())
					{
						if(!Tools.isEmpty(localRepeatImport.getType())){
							list.get(0).setType(!Tools.isEmpty(localRepeatImport.getType())?localRepeatImport.getType():"1");
						}
						localRepeatImportMapper.updateByPrimaryKey(list.get(0));
						return "1";
					}
					
					LocalRepeatImport info = new LocalRepeatImport();
					info.setUuid(UUIDGenerateUtil.generate());
					info.setType(!Tools.isEmpty(localRepeatImport.getType())?localRepeatImport.getType():"1");
					localRepeatImportMapper.insertSelective(info);
					return "2";
				} catch (Throwable e)
				{
					throw new BaseException(e.getMessage());
				}
	}

	@Override
	public BaseMapper<LocalRepeatImportExample, LocalRepeatImport, String> getMapper()
	{
		// TODO Auto-generated method stub
		return localRepeatImportMapper;
	}

	@Override
	public LocalRepeatImport queryLocalRepeatImport()
	{
		// TODO Auto-generated method stub
		LocalRepeatImport lc=localRepeatImportMapper.queryLocalRepeatImport();
		if(Tools.isEmpty(lc)){
			return null;
		}else{
			return lc;
		}
	}
	
	@Override
	public Boolean queryLocalRepeatImportStatus(){
			LocalRepeatImport lc=localRepeatImportMapper.queryLocalRepeatImport();
			if(Tools.isEmpty(lc)){
				return true;
			}else if("2".equals(lc.getType())){
				return false;
			}else{
				return true;
			}
	}
}
